package de.ret_world.openrpgstudio.eventengine.entity;

import com.artemis.Entity;
import com.artemis.EntityProcessingSystem;
import de.ret_world.openrpgstudio.engine.artemis.components.Location;
import org.jrabbit.base.input.KeyboardHandler;
import org.jrabbit.standard.game.managers.GameManager;
import org.jrabbit.standard.game.world.camera.Camera;
import org.lwjgl.input.Keyboard;

/**
 *
 * @author Emu
 */
public class PlayerSystem extends EntityProcessingSystem {

    public PlayerSystem() {
        super(PlayerComponent.class, Location.class);
    }

    @Override
    protected void process(Entity entity) {
        Location loc = entity.getComponent(Location.class);

        int fract = 35;
        
        Camera cam = GameManager.camera();
        if (KeyboardHandler.isKeyDown(Keyboard.KEY_A)) {
            loc.getPoint().setX(loc.getPoint().getX() - world.getDelta() / fract);
        }
        if (KeyboardHandler.isKeyDown(Keyboard.KEY_D)) {
            loc.getPoint().setX(loc.getPoint().getX() + world.getDelta() / fract);
        }
        if (KeyboardHandler.isKeyDown(Keyboard.KEY_W)) {
            loc.getPoint().setY(loc.getPoint().getY() - world.getDelta() / fract);
        }
        if (KeyboardHandler.isKeyDown(Keyboard.KEY_S)) {
            loc.getPoint().setY(loc.getPoint().getY() + world.getDelta() / fract);
        }
        cam.location().set(loc.getPoint().getX(), loc.getPoint().getY());
    }
    
}
